<template>
    <page-card title="管理">
        <div class="table-page-search-wrapper">
            <a-row type="flex"
                   style="margin-bottom:20px"
                   justify="end">
                <a-col v-if="hasPermission('add')"
                       flex="1">
                    <a-button type="primary"
                              icon="plus"
                              @click="handleSave()">
                        新增
                    </a-button>
                </a-col>

                <template>
                    <a-col>
                        <a-input-search v-model="queryParam.name"
                                        placeholder="角色名称"
                                        allow-clear
                                        @search="search"/>
                    </a-col>
                </template>
            </a-row>
        </div>
        <a-table :columns="columns"
                 :rowKey="(record, index) => index"
                 :data-source="data"
                 @change="handleTableChange"
                 :pagination="pagination">
            <span slot="action" slot-scope="text, record">
            <template v-if="hasPermission('edit')">
              <a @click="handleEdit(record.id)">编辑</a>
            </template>
            <template v-if="hasPermission('delete')">
              <a-divider type="vertical"/>
              <a-popconfirm title="确定要删除吗？"
                            ok-text="是"
                            cancel-text="否"
                            @confirm="handleDelete(record.id)">
                <a href="javascript:;">删除</a>
              </a-popconfirm>
            </template>
          </span>
        </a-table>
    </page-card>
</template>
<script>
import { leaveInfoList, leaveInfoDel } from '@/api/leaveinfo'
import { PAGINATION, TABLE_STATUS_CELL } from '@zt/zongheng-pro/framework/constants'

export default {
  data () {
    return {
      data: [],
      pagination: PAGINATION,
      statusCell: TABLE_STATUS_CELL,
      queryParam: {},
      columns: [
      {
        title: '',
        dataIndex: 'id'
      }
      ,
      {
        title: '关联系统sys_unituser表',
        dataIndex: 'unitUserId'
      }
      ,
      {
        title: '申请人',
        dataIndex: 'userName'
      }
      ,
      {
        title: '申请单位',
        dataIndex: 'deptName'
      }
      ,
      {
        title: '职务',
        dataIndex: 'userRole'
      }
      ,
      {
        title: '请假人性别',
        dataIndex: 'gender'
      }
      ,
      {
        title: '请假人年龄',
        dataIndex: 'age'
      }
      ,
      {
        title: '请假类型：婚假；年休；产假，等',
        dataIndex: 'leaveTypeId'
      }
      ,
      {
        title: '请假开始时间',
        dataIndex: 'startTime'
      }
      ,
      {
        title: '请假结束时间',
        dataIndex: 'endTime'
      }
      ,
      {
        title: '总的请假天数',
        dataIndex: 'totalDay'
      }
      ,
      {
        title: '年内休假情况',
        dataIndex: 'leaveDetail'
      }
      ,
      {
        title: '主持工作领导',
        dataIndex: 'leaderId'
      }
      ,
      {
        title: '主持工作领导职务',
        dataIndex: 'leaderPostId'
      }
      ,
      {
        title: '请假事由',
        dataIndex: 'leaveReason'
      }
      ,
      {
        title: '审批意见: 0:暂存；1:审批中；2：同意；3：不同意；4：拟同意',
        dataIndex: 'reviewComment'
      }
      ,
      {
        title: '审核人',
        dataIndex: 'reviewId'
      }
      ,
      {
        title: '',
        dataIndex: 'createTime'
      }
      ]
    }
  },
  created () {
    if (this.hasPermissions('edit', 'delete')) {
      this.columns.push({
        title: '操作',
        width: 130,
        align: 'center',
        scopedSlots: { customRender: 'action' }
      })
    }
  },
  activated () {
    this.load()
  },
  methods: {
    search () {
      this.pagination.current = 1
      this.load()
    },
    load () {
      this.queryParam.currPage = this.pagination.current
      this.queryParam.pageSize = this.pagination.pageSize
      leaveInfoList({ ...this.queryParam }).then((response) => {
        this.data = response.list
        this.pagination.current = response.currPage
        this.pagination.total = response.totalCount
        this.pagination.pageSize = response.pageSize
      })
    },
    handleTableChange (pagination, filters, sorter) {
      this.pagination = pagination
      this.load()
    },
    handleSave () {
      this.$router.push({
        path: 'add'
      })
    },
    handleEdit (id) {
      this.$router.push({
        path: 'edit',
        query: {
            id: id
        }
      })
    },
    handleDelete (id) {
      const data = []
      data.push(id)
      leaveInfoDel(data).then(() => {
        this.message.success('删除成功')
        this.load()
      })
    }
  }
}
</script>
